package com.csx.base.design.behavior.mediator;

/**
 * @author cuisongxu
 * @date 2022/10/11 12:09
 */
public class PrivateChatRoom extends ChatRoom{

    public PrivateChatRoom(String name) {
        super(name);
    }

    @Override
    protected void register(User user) {
        if(users.size() == 2) {
            System.out.println("聊天室已满");
            return;
        }
        super.register(user);
        System.out.print("系统消息: 欢迎 【" );
        System.out.print(user.getName());
        System.out.println("】 加入2人聊天室 【" + name + "】");
    }

    @Override
    protected void deregister(User user) {
        super.deregister(user);
        System.out.print("系统消息: " + user.getName() + "离开了聊天室");
    }

    @Override
    protected void sendMsg(User from, User to, String msg) {
        users.forEach(user -> user.listen(from, null, msg));
    }

    @Override
    protected String processMsg(User from, User to, String msg) {
        return from.getName() + "说: " + msg;
    }
}
